<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%String path = request.getContextPath();%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
	<title>微信签到系统-用户管理</title>
	<link rel="stylesheet" href="./css/bootstrap.css">
	<script src="./js/jquery.js"></script>
	<script src="./js/bootstrap.min.js"></script>
	<style>
		.control-group{
			margin-bottom:15px;
		}
		.table tr th,.table tr td{
			text-align: center;
		}
		.title h3{
			font-size:18px;
			margin:5px 0 5px 0;
			border-left:5px solid #eee;
			padding:3px 5px;
		}
		.noTask{
			margin-top:10px;
		}
	</style>
</head>
<body>

<nav class="navbar navbar-default navbar-fixed-top">
	<div class="container">
		<div class="navbar-header">
                 <button class="navbar-toggle" data-toggle="collapse" data-target="#navbarCollapse">
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
					<span class="icon-bar"></span>
                 </button>
                <a href="home" class="navbar-brand">微信签到系统</a>
          </div>
          <div class="collapse navbar-collapse" id="navbarCollapse">
			<ul class="nav navbar-nav" style="margin-top:0">
				<li><a href="home">控制台</a></li>
				<li class="active"><a href="#">签到统计</a></li>
				<li><a href="class?method=list">学生管理</a></li>
				<li><a href="notice?method=list">公告管理</a></li>
			</ul>
			 <p class="navbar-text navbar-right">
			 	${adminInfo.roleName }： <a href="#">${adminInfo.username }</a> | 
			 	<a href="adminManager?method=logout">退出</a>
			 </p>
		</div>
	</div>
</nav>
<div class="main container" style="margin-top:60px;">
		<form action="?" class="form-horizontal">
			<input type="hidden" id="currentSignId" value="${currentSignId}"/>
			<div class="form-group form-group-sm">
				<label class="col-md-2 col-xs-3 control-label" for="sginTask" style="text-align:left">
					选择签到任务
				</label>
				<div class="col-md-4  col-xs-8">
					<select  id="signId" class="select form-control" onchange="chooseSignTask(this)">
						<option value="-1">请选择</option>
						<c:forEach items="${signList}" var="obj">
							<option value="${obj.signId }">${obj.desc }</option>
						</c:forEach>
					</select>
				</div>
			</div>
		</form>
		
		<ul id="myTab" class="nav nav-tabs">
			<li class="active">
				<a href="#" data-toggle="tab">已签到</a>
			</li>
			<c:choose>
				<c:when test="${currentSignId!=null }">
					<li><a href="report?method=signNo&signId=${currentSignId}" >未签到</a></li>
					<li style="float:right"><a href="report?method=export&signId=${currentSignId}" class="btn btn-info btn-sm">导出为Excel文件</a></li>
				</c:when>
				<c:otherwise>
					<li><a href="javascript:alert('请先选择一个签到任务进行查看！')" >未签到</a></li>
				</c:otherwise>
			</c:choose>
			
		</ul>
		<div id="myTabContent" class="tab-content">
			<div class="tab-pane fade in active" id="home">
				<c:choose>
					<c:when test="${currentSignId==null }">
						<p class="noTask alert alert-danger">提示：请选择签到任务，查看签到统计！</p>
					</c:when>
					<c:otherwise>
							<div class="table-container table-responsive">
								<table class="table table-striped table-hover table-responsive">
									<thead>
									<tr>
										<th>编号</th>
										<th>学号</th>
										<th>姓名</th>
										<th>班级</th>
										<th>签到时间</th>
										<th>操作</th>
									</tr>
									</thead>
									<tbody>
									<c:choose>
										<c:when test="${page.list!=null && page.list.size()>0}">
											<c:forEach items="${page.list }" var="obj">
												<tr>
													<td>${obj.rid }</td>
													<td>${obj.stuNo }</td>
													<td>${obj.stuName }</td>
													<td>${obj.className }</td>
													<td>${obj.signTime }</td>
													<td>
														<a href="report?method=removeSignRecord&rid=${obj.rid }" 
														onclick="return removeSignRecord(this,'提示：确定删除该用户的本次签到记录么？')">移除</a> 
													</td>
												</tr>
											</c:forEach>
										</c:when>
										<c:otherwise>
												<tr>
													<td colspan="8">暂无数据...</td>
												</tr>
										</c:otherwise>
									</c:choose>
									</tbody>
								</table>
								</div>
							 <ul class="pagination" id="pageul">
							 	<c:choose>
									<c:when test="${page.pageNow == 1}">
										<li class='disabled'><span>首页</span></li>
										<li class='disabled'><span>上一页</span></li>
									</c:when>
									<c:otherwise>
										<li><a href="javascript:void(0)">首页</a></li>
										<li><a href="javascript:void(0)">上一页</a></li>
									</c:otherwise>
								</c:choose>
									<c:forEach begin="${(page.navNo -1)*5 + 1}" end="${page.totalPage > 5*page.navNo?5*page.navNo:page.totalPage}" var="s">
										<li <c:if test='${page.pageNow == s}'>class='active'</c:if>><a href="javascript:void(0)">${s}</a></li>
									</c:forEach>
									<c:choose>
										<c:when test="${page.pageNow == page.totalPage}">
											<li class='disabled'><span>下一页</span></li>
											<li class='disabled'><span val="${page.totalPage}">尾页</span></li>
										</c:when>
										<c:otherwise>
											<li><a href="javascript:void(0)">下一页</a></li>
											<li><a href="javascript:void(0)" val="${page.totalPage}">尾页</a></li>
										</c:otherwise>
									</c:choose>
									<li  class="disabled"><span class="hidden-xs">总记录:${page.totalSize} | 页码:${page.pageNow}/${page.totalPage}</span></li>
							 </ul>
							
					</c:otherwise>
				</c:choose>
				
			</div>
		</div>

</div>
<script>
	$(function(){
		$('#myTab li:eq(0) a').tab('show');
		$("a").tooltip({
			delay:{
				show:100,
				hide:100,
			},
			container:'body'
		});
		
		if("${currentSignId}"!=""){
			$("#signId").val("${currentSignId}");
		}
		pageul(${page.pageNow});
	})
	
	function chooseSignTask(thisObj){
		signId = $(thisObj).val();
		if(signId==-1){
			location.href = "report?method=list";
		}else{
			location.href = "report?method=signYes&signId="+signId;
		}
	}
	
	function removeSignRecord(thisObj,msg){
		var r  = confirm(msg);
		if(r){
			url = $(thisObj).attr("href");
			$.get(url,function(rsp){
				obj = $.parseJSON(rsp);
				if(obj.rspCode==0000){
					location.reload();
				}else{
					alert("操作失败："+obj.rspDesc);
				}
			});
		}
		return false;
	}
		/*初始化分页*/
	function pageul(page){
		$("#pageul > li > a").each(function() {
			$(this).click(function() {
				if ($(this).text() == '上一页') {
					showPage(page - 1);
					return;
				}else if ($(this).text() == '首页') {
					showPage(1);
					return;
				} else if ($(this).text() == '下一页') {
					showPage(page + 1);
					return;
				}else if ($(this).text() == '尾页') {
					showPage($(this).attr("val"));
					return;
				} else {
					showPage($(this).text());
				}
			});
		});
	}
		
	//分页	
	function showPage(pageNo){
		var currentSignId = $("#currentSignId").val();
		window.location.href="report?method=signYes&signId="+currentSignId+"&pageNo="+pageNo;
	}

</script>

</body>
</html>